import pygame

class ChessPiece:
    """棋子基类"""
    def __init__(self, color, name, row, col):
        """初始化棋子
        
        Args:
            color (str): 棋子颜色，"red" 或 "black"
            name (str): 棋子名称，如"車"、"马"等
            row (int): 行坐标
            col (int): 列坐标
        """
        self.color = color  # 颜色：red或black
        self.name = name    # 棋子名称
        self.row = row      # 行坐标
        self.col = col      # 列坐标
    
    def move_to(self, row, col):
        """移动棋子到新位置"""
        self.row = row
        self.col = col

class Ju(ChessPiece):
    """車/车"""
    def __init__(self, color, row, col):
        name = "车" if color == "black" else "車"
        super().__init__(color, name, row, col)

class Ma(ChessPiece):
    """馬/马"""
    def __init__(self, color, row, col):
        name = "马" if color == "black" else "馬"
        super().__init__(color, name, row, col)

class Xiang(ChessPiece):
    """相/象"""
    def __init__(self, color, row, col):
        name = "象" if color == "black" else "相"
        super().__init__(color, name, row, col)

class Shi(ChessPiece):
    """士/仕"""
    def __init__(self, color, row, col):
        name = "士" if color == "black" else "仕"
        super().__init__(color, name, row, col)

class King(ChessPiece):
    """将/帅"""
    def __init__(self, color, row, col):
        name = "将" if color == "black" else "帅"
        super().__init__(color, name, row, col)

class Pao(ChessPiece):
    """炮"""
    def __init__(self, color, row, col):
        super().__init__(color, "炮", row, col)

class Pawn(ChessPiece):
    """兵/卒"""
    def __init__(self, color, row, col):
        name = "卒" if color == "black" else "兵"
        super().__init__(color, name, row, col)

def create_initial_pieces():
    """创建初始布局的所有棋子
    
    Returns:
        list: 所有棋子的列表
    """
    pieces = []
    
    # 黑方(上方)
    pieces.append(Ju("black", 0, 0))
    pieces.append(Ma("black", 0, 1))
    pieces.append(Xiang("black", 0, 2))
    pieces.append(Shi("black", 0, 3))
    pieces.append(King("black", 0, 4))
    pieces.append(Shi("black", 0, 5))
    pieces.append(Xiang("black", 0, 6))
    pieces.append(Ma("black", 0, 7))
    pieces.append(Ju("black", 0, 8))
    pieces.append(Pao("black", 2, 1))
    pieces.append(Pao("black", 2, 7))
    pieces.append(Pawn("black", 3, 0))
    pieces.append(Pawn("black", 3, 2))
    pieces.append(Pawn("black", 3, 4))
    pieces.append(Pawn("black", 3, 6))
    pieces.append(Pawn("black", 3, 8))
    
    # 红方(下方)
    pieces.append(Ju("red", 9, 0))
    pieces.append(Ma("red", 9, 1))
    pieces.append(Xiang("red", 9, 2))
    pieces.append(Shi("red", 9, 3))
    pieces.append(King("red", 9, 4))
    pieces.append(Shi("red", 9, 5))
    pieces.append(Xiang("red", 9, 6))
    pieces.append(Ma("red", 9, 7))
    pieces.append(Ju("red", 9, 8))
    pieces.append(Pao("red", 7, 1))
    pieces.append(Pao("red", 7, 7))
    pieces.append(Pawn("red", 6, 0))
    pieces.append(Pawn("red", 6, 2))
    pieces.append(Pawn("red", 6, 4))
    pieces.append(Pawn("red", 6, 6))
    pieces.append(Pawn("red", 6, 8))
    
    return pieces 